package com.servlet.web;

import com.servlet.bean.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

/**
 * @Title: ResponseServlet04
 * @Description:
 * @Auther: py
 * @Version: 1.0
 * @create 2023/12/22 10:16
 */
@WebServlet("/resp04")
public class ResponseServlet04 extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
         // 设置响应状态码
        // resp.setStatus(500);
        //  设置响应状态码以及错误页面
        resp.setHeader("Content-Type","text/plain;charset=utf-8");
        resp.sendError(500,"服务器异常！");
        // 重定向

        // 设置响应的类型 text/plain 文本类型 text/html 超文本类型 application/json json类型
        resp.setHeader("Content-Type","text/plain;charset=utf-8");
        resp.getWriter().write("响应成功!");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req,resp);
    }
}
